﻿function ApartmentInfo(data){
    this.ApartmentId = data['ApartmentId'];
    this.ShortName = data['ShortName'];
    this.LongName = data['LongName'];
    this.Url = data['Url'];
    this._img = data['ImageUrlPattern'];

    this.GetImageUrlBoxed = function (width, height) {
        var url = this._img;
        url = url.replace('0x0', width + 'x' + height);
        return url;
    }
}

function GetAllApartments(callback) {
    if (window.Apartments) {
        if (callback)
            callback(window.Apartments);
        return;
    }
    $.ajax({
        type: "POST",
        url: "/Handlers/BlackApartService.asmx/GetAllApartments",
        data: "{}",
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        success: function (msg) {
            var apartments = new Array();
            for (var xa = 0; xa < msg['d'].length; xa++) {
                apartments.push(new ApartmentInfo(msg['d'][xa]));
            }
            window.Apartments = apartments;
            if (callback)
                callback(apartments);
        }
    });
}